<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>响应式图片示例</title>
    <style>
        :root {
            --container-width: 1200px;
            --container-padding: 1rem;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
            line-height: 1.6;
            color: #333;
            background: #f8f9fa;
        }

        .container {
            max-width: var(--container-width);
            margin: 0 auto;
            padding: var(--container-padding);
        }

        .header {
            text-align: center;
            margin: 2rem 0;
        }

        /* 基础响应式图片 */
        .responsive-img {
            max-width: 100%;
            height: auto;
            display: block;
            margin: 0 auto;
        }

        /* 图片容器 */
        .img-container {
            margin-bottom: 2rem;
            background: white;
            padding: 1rem;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }

        .img-title {
            margin-bottom: 1rem;
            color: #2c3e50;
        }

        .img-description {
            margin-top: 1rem;
            color: #7f8c8d;
            font-size: 0.9rem;
        }

        /* 艺术指导示例 */
        .art-direction {
            position: relative;
            height: 300px;
            background: #3498db;
            margin-bottom: 2rem;
            overflow: hidden;
        }

        .art-direction img {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        /* 响应式背景图片 */
        .bg-image {
            height: 400px;
            background-image: url('path/to/large.jpg');
            background-size: cover;
            background-position: center;
            margin-bottom: 2rem;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            text-align: center;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
        }

        @media (max-width: 768px) {
            .bg-image {
                background-image: url('path/to/medium.jpg');
                height: 300px;
            }
        }

        @media (max-width: 480px) {
            .bg-image {
                background-image: url('path/to/small.jpg');
                height: 200px;
            }
        }

        /* 图片网格 */
        .image-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 1rem;
            margin-bottom: 2rem;
        }

        .grid-item {
            position: relative;
            padding-bottom: 75%; /* 4:3 宽高比 */
            overflow: hidden;
            border-radius: 8px;
        }

        .grid-item img {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.3s ease;
        }

        .grid-item:hover img {
            transform: scale(1.1);
        }

        /* 延迟加载占位符 */
        .lazy-image {
            background: #eee;
            position: relative;
        }

        .lazy-image::before {
            content: '';
            display: block;
            padding-top: 56.25%; /* 16:9 宽高比 */
        }

        .lazy-image img {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .lazy-image img.loaded {
            opacity: 1;
        }
    </style>
</head>
<body>
    <div class="container">
        <header class="header">
            <h1>响应式图片技术示例</h1>
            <p>展示不同的响应式图片实现方式</p>
        </header>

        <!-- 基础响应式图片 -->
        <section class="img-container">
            <h2 class="img-title">基础响应式图片</h2>
            <img 
                src="path/to/image.jpg"
                alt="响应式图片示例"
                class="responsive-img"
            >
            <p class="img-description">使用max-width: 100%和height: auto实现基础的响应式图片</p>
        </section>

        <!-- srcset和sizes属性示例 -->
        <section class="img-container">
            <h2 class="img-title">使用srcset和sizes</h2>
            <img 
                srcset="
                    path/to/small.jpg 300w,
                    path/to/medium.jpg 600w,
                    path/to/large.jpg 900w
                "
                sizes="
                    (max-width: 320px) 280px,
                    (max-width: 640px) 580px,
                    800px
                "
                src="path/to/fallback.jpg"
                alt="使用srcset的响应式图片"
                class="responsive-img"
            >
            <p class="img-description">使用srcset和sizes属性让浏览器选择最适合的图片版本</p>
        </section>

        <!-- picture元素示例 -->
        <section class="img-container">
            <h2 class="img-title">使用picture元素</h2>
            <picture>
                <source 
                    media="(min-width: 800px)"
                    srcset="path/to/desktop.jpg"
                >
                <source 
                    media="(min-width: 400px)"
                    srcset="path/to/tablet.jpg"
                >
                <img 
                    src="path/to/mobile.jpg" 
                    alt="使用picture元素的响应式图片"
                    class="responsive-img"
                >
            </picture>
            <p class="img-description">使用picture元素实现艺术指导</p>
        </section>

        <!-- 响应式背景图片 -->
        <section class="bg-image">
            <div>
                <h2>响应式背景图片</h2>
                <p>使用媒体查询切换不同尺寸的背景图片</p>
            </div>
        </section>

        <!-- 图片网格 -->
        <section>
            <h2 class="img-title">响应式图片网格</h2>
            <div class="image-grid">
                <div class="grid-item">
                    <img src="path/to/grid-1.jpg" alt="网格图片1">
                </div>
                <div class="grid-item">
                    <img src="path/to/grid-2.jpg" alt="网格图片2">
                </div>
                <div class="grid-item">
                    <img src="path/to/grid-3.jpg" alt="网格图片3">
                </div>
            </div>
        </section>

        <!-- 延迟加载示例 -->
        <section>
            <h2 class="img-title">图片延迟加载</h2>
            <div class="lazy-image">
                <img 
                    data-src="path/to/lazy-image.jpg"
                    alt="延迟加载图片"
                    loading="lazy"
                >
            </div>
        </section>
    </div>

    <script>
        // 图片延迟加载
        document.addEventListener('DOMContentLoaded', function() {
            const lazyImages = document.querySelectorAll('img[data-src]');
            
            const imageObserver = new IntersectionObserver((entries, observer) => {
                entries.forEach(entry => {
                    if (entry.isIntersecting) {
                        const img = entry.target;
                        img.src = img.dataset.src;
                        img.addEventListener('load', () => {
                            img.classList.add('loaded');
                        });
                        observer.unobserve(img);
                    }
                });
            });

            lazyImages.forEach(img => imageObserver.observe(img));
        });
    </script>
</body>
</html>
